#include "rotator.h"

Rotator_Define::Rotator_Define(double process_speed,int group_idx)
    :FacilityDefine(
        FacilityType::ROTATER,
        process_speed,
        1,
        1,
        1,
        1,
        group_idx
        )
{
    relative_exits.push_back(ExitGate(Coordinate(0,0),gate::Gate_UP));
    relative_enters.push_back(EnterGate(Coordinate(0,0),gate::Gate_DOWN));
}

Rotator::Rotator(FacilityDefine *define, FacilityDirection f_dir, Coordinate coordinate, Cargo_Manager * cargo_manager)
:Facility(define,f_dir,coordinate,cargo_manager)
{

}
void Rotator::finishProcess(){
    Cargo * c = cargo_manager->turnDirection(incargos[0],define->getGroupIdx());
    switch (c->define->cargo_type) {
    case CargoType::COLOR:
        cargo_manager->paintColorCargo(abs_exits[0].position.x,abs_exits[0].position.y,abs_exits[0].direction,(ColorCargo*)c);
        break;
    case CargoType::SHAPE:
        cargo_manager->paintShapeCargo(abs_exits[0].position.x,abs_exits[0].position.y,abs_exits[0].direction,(ShapeCargo*)c);
        break;
    default:
        break;
    }
    delete incargos[0];
    incargos[0] = null;
    outcargos[0] = c;
    sendCargo();
    Facility::finishProcess();
}
